package org.jsola.hr.web;


import org.jsola.core.Result;
import org.jsola.hr.constant.HrConstants;
import org.jsola.hr.dto.SocAccountDTO;
import org.jsola.hr.service.ISocCacheService;
import org.jsola.user.core.TokenUser;
import org.jsola.user.core.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 社保缓存相关
 *
 * @author lyh
 */
@RestController("hrSocCacheController")
@RequestMapping(HrConstants.API_PATH + "/v1/socCache")
public class SocCacheController implements ISocCacheControllerAPI {

    @Autowired
    private ISocCacheService socCacheService;

    @Override
    @PostMapping
    public Result<String> setSocAccountCache(@Valid @RequestBody SocAccountDTO socAccountDTO) {
        TokenUser tokenUser = UserContext.getUser();
        // todo 登陆的社保账户入缓存权限校验

        socCacheService.setSocAccountCache(socAccountDTO, tokenUser);
        return Result.success();
    }

    @Override
    @GetMapping
    public Result<List<SocAccountDTO>> getSocAccount(@RequestParam(value = "areaId",required = false) String areaId) {
        TokenUser tokenUser = UserContext.getUser();
        // todo 新增员工考勤记录权限校验
        return Result.success(
                socCacheService.getSocAccount(areaId, tokenUser)
        );
    }

    @Override
    @GetMapping("/deceive")
    public Result<Boolean> deceive(@RequestParam(value = "deceive",required = false) Boolean deceive) {
        return Result.success(
                socCacheService.deceive(deceive)
        );
    }
}
